const { data } =  require('../mock')
const bodyParser = require('body-parser')

module.exports= app => {
    app.use(bodyParser.json())

    app.post('/api/getList', (req, res) => {
        let { type,  current} = req.body

        type = type * 1

        const newData = data
        .filter(item => item.type === type)
        .filter((item,idx) => idx < current * 10)
        
        res.send({
            data: newData,
            code: 0
        })
    })

    app.post('/api/getDetail', (req, res) => {
        const { id } = req.body;

        res.send({
            data: data.find(item => item.id === id),
            code: 0
        })
    })
}
